import axios from 'axios'

interface user_detail {
  id: string
  username: string
  password: string
  sex: string
  icon: string
  email: string
  mobile: string
  nick_name: string
  note: string
  highest_role_name: string
  workplace: string
  research: string
}

const user_api = {
  // 普通用户下载历史记录
  async get_download_record(param_current_page: number) {
    const response = await axios.get('/api/dataset_download/normal/history', {
      params: {
        current_page: param_current_page,
      },
    },
    )

    return response.data
  },

  // 普通用户的删除(即注销）
  async log_off(param_user_id: string) {
    const response = await axios.delete('/api/normal/account/delete', {
      params: {
        user_id: param_user_id,
      },
    },
    )

    return response.data
  },

  // 普通用户修改用户信息时展示内容
  async get_user_info() {
    const response = await axios.get('/api/normal/account/edit_show')

    return response.data
  },

  // 普通用户修改信息后保存
  async save_user_info(param_user_info: user_detail) {
    const response = await axios.put('/api/normal/account/edit_save', {
      id: param_user_info.id,
      username: param_user_info.username,
      sex: param_user_info.sex,
      icon: param_user_info.icon,
      email: param_user_info.email,
      mobile: param_user_info.mobile,
      nick_name: param_user_info.nick_name,
      note: param_user_info.note,
      workplace: param_user_info.workplace,
      research: param_user_info.research,
    },
    )

    return response.data
  },

  // 普通用户下载订单展示
  async get_apply_record(param_current_page: number, param_page_size: number) {
    const response = await axios.get('/api/dataset_download/normal/order_list', {
      params: {
        current_page: param_current_page,
        page_size: param_page_size,
      },
    })

    return response.data
  },

  // 普通用户的下载
  async dataset_download(param_order_id: string) {
    const response = await axios.get('/api/dataset_download/normal/down', {
      params: {
        order_id: param_order_id,
      },
    })

    return response.data
  },

  // 普通用户修改密码
  async modify_password(param_password: string) {
    const response = await axios.post('/api/normal/account/renew_password', {
      new_password: param_password,
    })

    return response.data
  },
}

export default user_api
